<template>
  <div class="drawer-container">


    <!-- 控制按钮 -->
    <div class="drawer-control" @click="toggleDrawer">
      <i v-if="!drawer" class="el-icon-menu"></i>
      <i v-else class="el-icon-close"></i>
    </div>



      <el-drawer
        title="监测主题"
        :visible.sync="drawer"
        :direction="direction"
        size="15%"
        :modal="false"
        :with-header="false"
      >


        <div style="background-color: white;padding: 10px;height: 100%;">
          <el-input
            clearable
            placeholder="请输入主题名称"
            prefix-icon="el-icon-search"
            size="small"
            style="margin-bottom: 20px;width: 100%"
            v-model="searchTopicName"
          />

          <div
            style="padding: 10px;min-height: 730px">

            <!--主题数据-->

            <el-tabs :tab-position="tabPosition" @tab-click="handleClick">
              <el-tab-pane :label="item.title" v-for="(item,index) in topicList" :key="index">


                <template slot="label">

                  <span style="margin-right: 10px">{{ item.title }}</span>

                  <el-button
                    size="mini"
                    type="text"
                    style="color:black"
                    icon="el-icon-edit"
                    @click="handleUpdate(item)"
                    v-hasPermi="['system:topic:edit']"
                  >
                  </el-button>
                  <el-button
                    size="mini"
                    type="text"
                    style="color:black"
                    icon="el-icon-delete"
                    @click="handleDelete(item)"
                    v-hasPermi="['system:topic:remove']"
                  >
                  </el-button>

                </template>

                <div>

                  <!-- Tab content here -->

                </div>


              </el-tab-pane>

            </el-tabs>


          </div>

          <el-button @click="createTopic" icon="el-icon-plus" style=" width: 100%;bottom: 0" type="primary" plain
                     size="small"
                     v-hasPermi="['system:topic:add']">新建主题
          </el-button>


        </div>


      </el-drawer>


    <el-scrollbar style="height: calc(100vh - 88px);">
      <OpinionDetail :topicId="selectTopicId" :topicName="topicName" v-if="selectTopicId!=0"></OpinionDetail>
    </el-scrollbar>




  </div>
</template>

<script>
  import {delTopic, listTopic, updateTopic} from "@/api/system/topic";
  import OpinionDetail from '@/views/monitoring/topic/detail'

  export default {
    name: "Topic",
    components: {OpinionDetail},
    data() {
      return {
        tabPosition: 'left',
        drawer: true,
        direction: 'ltr',
        params: {type: "comprehensive"},
        defaultProps: {
          children: "children",
          label: "label"
        },
        // 主题名称
        topicName: null,
        searchTopicName: null,
        topicList: [],
        selectTopicId: 0,

      };
    },
    watch: {
      // 根据名称筛选部门树
      searchTopicName(val) {
        this.params.title = val
        this.getList()
      }
    },
    created() {
      this.getList()
    },
    methods: {
      handleClick(tab, event) {
        let topic = this.topicList[tab.index]
        this.selectTopicId = topic.id
        this.topicName = topic.title
      },
      toggleDrawer() {
        this.drawer = !this.drawer;
      },


      handleUpdate(row) {
        this.$router.push({
          path: '/monitoring/create',
          query: {
            id: row.id,
            title: row.title,
            searchArea: row.searchArea,
            relatedWords: row.relatedWords,
            exclusionWords: row.exclusionWords,
            opinionWords: row.opinionWords,
            monitoringEmotion: row.monitoringEmotion,
            monitoringMedia: row.monitoringMedia,
          },
          meta: {
            title: '修改监测主题',
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id
        this.$confirm('是否确认删除主题名称为【' + row.title + '】的主题?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return delTopic(ids);
        }).then(response => {
          if (response.data < 0) {
            this.msgInfo("请先删除子主题");
          } else {
            this.getList();
            this.msgSuccess("删除成功");
          }
        })
      },


      createTopic() {
        this.$router.push({path: '/monitoring/create'});
      },

      /** 查询模版组件列表 */
      getList() {
        this.loading = true;
        listTopic(this.params).then(response => {
          this.topicList = response.rows;
          if (this.topicList.length > 0) {
            let topic = this.topicList[0]
            this.selectTopicId = topic.id
            this.topicName = topic.title
          }
          this.loading = false;
        });
      },


    }
  };
</script>

<style lang="scss" scoped>
  .bg {
    background-color: #eeeeee;
    position: relative; /* 设置相对定位，以便子元素可以相对于它定位 */
    overflow: hidden; /* 防止滚动条出现 */
  }

  .box {
    padding: 20px;
    border: 1px solid #e5e6e7;
    background: #FFFFFF none;
    border-radius: 4px;
    margin-bottom: 10px;
  }

  .relatedWords {
    color: #5d5d5d;
    margin-top: 10px;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    height: 40px;
  }

  .date {
    color: #5d5d5d;
    margin-top: 10px;
    font-size: 14px;
  }

  ::v-deep .el-drawer.ltr {
    top: 98px;
    right: 0;
    width: 20%;
  }

  .el-drawer {
    z-index: 1000; /* 确保抽屉显示在其他内容之上 */
  }


  .drawer-control {
    display: flex;
    align-items: center; /* 垂直居中 */
    justify-content: center; /* 水平居中 */
    width: 50px;
    height: 50px;
    background-color: #C0C0C0;
    border-radius:30px;
    border: 1px solid #C0C0C0;
    position: absolute; /* 绝对定位 */
    top: 50%; /* 垂直居中 */
    right: 36px; /* 根据需要调整距离 */
    cursor: pointer;
    z-index: 1001; /* 确保图标在抽屉之上 */
  }

  .drawer-control i {
    font-size: 24px; /* 图标大小 */
    color: #07c160; /* 图标颜色 */
  }

  /* 当抽屉打开时，可以隐藏控制按钮或调整其位置 */
  .el-drawer__open .drawer-control {
    right: calc(30% + 36px); /* 根据抽屉大小和距离调整 */
  }


  ::v-deep .el-tabs--left .el-tabs__nav-wrap.is-left::after, .el-tabs--left .el-tabs__nav-wrap.is-right::after, .el-tabs--right .el-tabs__nav-wrap.is-left::after, .el-tabs--right .el-tabs__nav-wrap.is-right::after {
    width: 0;
  }

  ::v-deep .el-tabs__content {
    height: 40px;
    width: 0;
    line-height: 40px;
  }

  ::v-deep .el-tabs__item.is-active {
    background-color: #1a5cd7;
    color: white;
  }

  ::v-deep .el-tabs__item {
    background-color: #eeeeee;

  }

  ::v-deep .el-tabs--left .el-tabs__header.is-left {
    width: 100%;
    float: left;
    margin-bottom: 0;
    margin-right: 10px;
  }

</style>
